#include "fdt_net.h"
#include "fdt_daemon.h"
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

static int udp_msg_handler(struct fdt_socket* sock)
{
    char buf[256] = {0};
    int len = 0;

    fdt_sock_send_msg(sock, buf, len);
     // processing...
}

static struct fdt_sock_cb udp_cb = {
    .func = udp_msg_handler
};

int main()
{
    struct fdt_socket udpsock;
    struct fdt_daemon dm;
    struct sockaddr_in daddr;

    //set dest address
    memset(&daddr, 0, sizeof(daddr)); 
    daddr.sin_family = AF_INET;
    daddr.sin_port = htons(50001);
    daddr.sin_addr.s_addr = inet_addr("192.168.1.45"); 
    
    make_udp_socket(&udpsock, (struct sockaddr_in*)&daddr, sizeof(daddr));

    fdt_sock_open(&udpsock, O_NONBLOCK);

    char buf[256] = {0};
    int len = 0;
    //...prepare mesg

    fdt_sock_send_msg(&udpsock, buf, len);

    if (fdt_sock_poll(&udpsock, NULL) > 0)
    {
        fdt_sock_recv_msg(&udpsock, buf, 256);
        // processing..
    }

    fdt_daemon_init(&dm);
    /*
     * add fdt socket to daemon and start the daemon
     */
    fdt_daemon_add_socket(&dm, &udpsock, &udp_cb);

    fdt_daemon_start(&dm);

    return 0;
}
